package ca.ryerson.rms.web;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class TabTaglib  extends TagSupport
{
	private static final long serialVersionUID = 2478639076925890108L;
	private String href;
	private String active="false";
	
	public void setHref(String href) {
		this.href = href;
	}

	public void setActive(String active) {
		this.active = active;
	}

	public int doStartTag() throws JspException
	{
		try{
			JspWriter out = pageContext.getOut();
			if(active.toLowerCase().trim().equals("true"))
			{
				out.write("<li class=\"active\">");
			}
			else
			{
				out.write("<li>");
			}
			out.write("<a href=\"" + href + "\">");
		}
		catch(IOException e){  
			e.printStackTrace();  
		}
		
		return EVAL_PAGE;
	}
	
	public int doEndTag() throws JspException
	{
		try
		{
			JspWriter out = pageContext.getOut();

			out.write("</a></li>");
		} 
		catch (IOException e) {
			throw new JspException(e);
		}
		
		return EVAL_PAGE;
    }
}
